home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 June: Reference Library / Dev.CD Jun 95 / Dev.CD Jun 95.toast / What's New? / New System Software Extensions / QuickDraw 3D ß / Programming / Unsupported Libraries / CustomIO_Lib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-24  |  3.9 KB  |  177 lines  |  [TEXT/MPS ]

  1. /*
  2.  * CustomIO_Lib.c
  3.  *
  4.  *    Demo/Template for writing custom IO functions
  5.  *    
  6.  *    Custom Attribute example
  7.  */
  8. #include "QD3D.h"
  9. #include "QD3DSet.h"
  10.  
  11. #include "QD3DIO.h"
  12.  
  13. #include "CustomIO_Lib.h"
  14.  
  15. /*
  16.  * Globals
  17.  */
  18. static TQ3ObjectClass gCustomAttributeClass;
  19.  
  20. /*
  21.  * Static Functions
  22.  */
  23.  
  24. static TQ3Status CustomAttribute_Traverse(
  25.     CustomAttributeRecord    *customAttribute,
  26.     TQ3FileObject            file)
  27. {
  28.     if (customAttribute->clickModel == NULL)
  29.         return kQ3Success;
  30.  
  31.     if (Q3FileWriteState_SetObjectWriteData(
  32.         file, customAttribute, sizeof(TQ3Uns32)) == kQ3Failure)
  33.     {
  34.         return kQ3Failure;
  35.     }
  36.     if (Q3FileWriteState_TraverseSubObject(
  37.         file, customAttribute->clickModel) == kQ3Failure)
  38.     {
  39.         return kQ3Failure;
  40.     }
  41.     return kQ3Success;
  42. }
  43.  
  44. static TQ3Status CustomAttribute_Write(
  45.     CustomAttributeRecord    *customAttribute,
  46.     TQ3FileObject            file)
  47. {
  48.     return 
  49.         Q3Uns32_Write((TQ3Uns32) customAttribute->isOn, file) == kQ3Success &&
  50.         Q3Comment_Write("isOn", file) == kQ3Success ? kQ3Success : kQ3Failure;
  51. }
  52.  
  53. static TQ3Status CustomAttribute_ReadData(
  54.     TQ3AttributeSet            attributeSet,
  55.     TQ3FileObject            file)
  56. {
  57.     CustomAttributeRecord    customAttribute;
  58.     TQ3ObjectType            type;
  59.     TQ3Boolean                remains;
  60.     TQ3Status                status;
  61.     
  62.     if (Q3Uns32_Read((TQ3Uns32 *) &customAttribute.isOn, file) == kQ3Failure)
  63.         return kQ3Failure;
  64.  
  65.     customAttribute.clickModel = NULL;
  66.     
  67.     if (Q3FileReadState_SubObjectsRemain(file, &remains) == kQ3Failure)
  68.         return kQ3Failure;
  69.     
  70.     if (remains == kQ3True) {
  71.         if (Q3FileReadState_AddSubObjectFilter(file, kQ3GroupTypeDisplay) == kQ3Failure)
  72.             return kQ3Failure;
  73.     
  74.         if (Q3FileReadState_ReadSubObject(file, &type, &customAttribute.clickModel) == kQ3Failure)
  75.             return kQ3Failure;
  76.     
  77.         if (type != kQ3GroupTypeDisplay) {
  78.             if (customAttribute.clickModel != NULL) {
  79.                 Q3Object_Dispose(customAttribute.clickModel);
  80.                 customAttribute.clickModel = NULL;
  81.             }
  82.         }
  83.     }
  84.         
  85.     status = Q3Set_Add(attributeSet, kCustomAttributeType, &customAttribute);
  86.  
  87.     if (customAttribute.clickModel)
  88.         Q3Object_Dispose(customAttribute.clickModel);
  89.  
  90.     return status;
  91. }
  92.  
  93. static TQ3Status CustomAttribute_CopyAdd(
  94.     CustomAttributeRecord    *src,
  95.     CustomAttributeRecord    *dst)
  96. {
  97.     *dst = *src;
  98.     if (dst->clickModel != NULL) 
  99.         Q3Shared_GetReference(dst->clickModel);
  100.     
  101.     return kQ3Success;
  102. }
  103.  
  104. static TQ3Status CustomAttribute_CopyReplace(
  105.     CustomAttributeRecord    *src,
  106.     CustomAttributeRecord    *dst)
  107. {
  108.     if (src->clickModel != NULL)
  109.         Q3Shared_GetReference(src->clickModel);
  110.     if (dst->clickModel != NULL) 
  111.         Q3Object_Dispose(dst->clickModel);
  112.  
  113.     *dst = *src;
  114.  
  115.     return kQ3Success;
  116. }
  117.  
  118. static TQ3Status CustomAttribute_Delete(
  119.     CustomAttributeRecord    *src)
  120. {
  121.     if (src->clickModel != NULL) 
  122.         Q3Object_Dispose(src->clickModel);
  123.     return kQ3Success;
  124. }
  125.  
  126. TQ3Status CustomAttribute_Unregister(
  127.     void)
  128. {
  129.     if ( gCustomAttributeClass != NULL )
  130.         return    Q3ObjectClass_Unregister(gCustomAttributeClass);
  131.         
  132.     return kQ3Failure;
  133. }
  134.  
  135. /*
  136.  * CustomAttribute_MetaHandler
  137.  */
  138. static TQ3FunctionPointer CustomAttribute_MetaHandler(
  139.     TQ3MethodType        methodType)
  140. {
  141.     switch (methodType)
  142.     {
  143.         case kQ3MethodTypeObjectTraverse:
  144.             return (TQ3FunctionPointer) CustomAttribute_Traverse;
  145.         case kQ3MethodTypeObjectWrite:
  146.             return (TQ3FunctionPointer) CustomAttribute_Write;
  147.         case kQ3MethodTypeObjectReadData:
  148.             return (TQ3FunctionPointer) CustomAttribute_ReadData;
  149.         case kQ3MethodTypeElementCopyAdd:
  150.         case kQ3MethodTypeElementCopyGet:
  151.         case kQ3MethodTypeElementCopyDuplicate:
  152.             return (TQ3FunctionPointer) CustomAttribute_CopyAdd;
  153.         case kQ3MethodTypeElementCopyReplace:
  154.             return (TQ3FunctionPointer) CustomAttribute_CopyReplace;
  155.         case kQ3MethodTypeElementDelete:
  156.             return (TQ3FunctionPointer) CustomAttribute_Delete;
  157.         default:
  158.             return (TQ3FunctionPointer) NULL;
  159.     }
  160. }
  161.  
  162. /*
  163.  * CustomAttribute_Register
  164.  */
  165. TQ3Status CustomAttribute_Register(
  166.     void)
  167. {
  168.     gCustomAttributeClass = 
  169.         Q3ElementClass_Register(
  170.             kCustomAttributeType,
  171.             "CustomAttribute",
  172.             sizeof(CustomAttributeRecord),
  173.             CustomAttribute_MetaHandler);
  174.  
  175.     return (gCustomAttributeClass == NULL ? kQ3Failure : kQ3Success);
  176. }
  177.